library(foreign)
library(ggplot2)
library(grid)
library(gridExtra)
library(scales)

rm(list=ls())

setwd("Yourpath")

source("fine_grid.R") # ggplot layers
source("summarySE.R") # summary stats (for figure 5)

#################################################
# Plot synth and did weights
#################################################


knum1 = read.csv("W_reg2.txt", sep = "\t")[,1]
knum2 = read.csv("W_weights_nonannual.txt", sep = "\t")[,2]
cbind(knum1,knum2)

W_reg2 = read.csv("W_reg2.txt", sep = "\t")[,2]
W_weights_nonannual = read.csv("W_weights_nonannual.txt", sep = "\t")[,3]

ct_label=c("BE","LU","UR","SZ","OW","NW","ZG","FR","SO","BS","BL","VS","NE","GE")


ct_breaks=c(1:length(ct_label))

df <- data.frame(weight=c(W_reg2,W_weights_nonannual),
                 group=c(matrix("Panel Model ",length(W_reg2),1), matrix("Synthetic Control Model",length(W_reg2),1)), 
                 canton=c(knum1,knum1), 
                 ct_breaks=c(ct_breaks,ct_breaks), 
                 ct_label=c(ct_label,ct_label) )

df$X1 = with(df, factor(ct_label, levels = rev(levels(ct_label))))

ggplot(df,aes(x=weight,y=factor(X1),shape=group)) +  
  geom_point(size=7.5) +
  #geom_text(aes(label=refnum,y=gap-2,x=x)) +
  theme_bw_finegrid(base_size = 32) +       
  ylab("") + xlab("Weight")  +
  scale_x_continuous(limits=c(-1.5,1.7),breaks=c(seq(-1.5,1.5,0.5))) +
  scale_y_discrete() +
  scale_shape_manual(values=c(2,16)) +
  geom_vline(x=0,linetype="dashed")+
  geom_vline(x=1,linetype="dashed") +  
  theme(legend.direction = "horizontal", legend.position = "bottom") +
  labs(fill="") + 
  theme(legend.title=element_blank())  


ggsave(file="Figure9.pdf",width=15,height=15 )

